<!DOCTYPE html>
<html>
<head>
<head/>
<div th:include="base-libs :: base-libs" />
<div th:include="common/yljg-modal :: yljg-modal" />
<div th:include="common/common-export :: common-export" />
<title>签约申请</title>
<style type="text/css">

/* .form-table button{
	margin-top: 2px;
} */
	.laydate-icon{
		border:1px solid #B6B6B6
	}
</style>
</head>
<script th:inline="javascript">
	/**用户信息*/
	var userInfo = [[${userInfo}]];
</script>
<script type="text/javascript">
$(function() {
	$(this).registerManagerPage();
	enterToQuery(queryForm);
 	initView();
});

function queryForm() {
	$("#qysqForm").datagrid("reload");
	/**禁用更新按钮*/
	if($("#btnUpdate").attr("disabled")!="disabled"){
		$("#btnUpdate").attr("disabled", "disabled");
	}
	/**清空勾选*/
	selectionIds = [];
}

function initView()
{
	//$(".cacheTable").CacheForSelect();
	var opt ={
			idField : "YLJGID",
			uniqueId: "YLTID",
			striped : true,
			border:false,
			toolbar : "#dgFormToolbar",
			columns : [[
// 				{
// 					field: "checkStatus",
// 					checkbox: true
// 				},
				{
					field : "YLTMC",
					width: 150,
					align: "center",
					title : "医联体名称"
				},
				{
					field : "ZDYLJGMC",
					width: 200,
					align: "center",
					title : "主导机构"
				},
				
				{
					field : "YLJGMC",
					width: 200,
					align: "center",
					title : "签约机构"
				},
				{
					field : "YLTLXMC",
					width: 100,
					align: "center",
					title : "医联体类型"
				},
				{
					field : "CJSJ",
					width: 100,
					align: "center",
					title : "申请时间",
					formatter : function(value, row, index){
						if(!StringUtils.isEmpty(value)){
							value = value.substr(0, 10);
						}
						return value;
					}
				},
				{
					field : "QYYXQMC",
					width: 100,
					align: "center",
					title : "签约有效期",
				},
				{
					field : "QYZT",
					width: 100,
					align: "center",
					title : "状态",
					formatter : function(value, row, index){
						return getZt(value);
					}
				},
				{
					field : "cz",
					width: 100,
					align: "center",
					title : "操作",
					formatter : operateFormatter
				}
			]]
			,pagination : true
			,pageNumber: 1
			,pageSize: 10
			,fit: true
			,fitColumns: true
			,singleSelect: true
			,rownumbers: true
			,method : "post"
			,url: contextRoot+"qysq/queryPage.service"
			,onBeforeLoad:function(params){
				params["YLJGID"] = $("#YLJGID").val();
				params["YLTLX"] = $("#YLTLX").val();
				params["CJSJ"] = $("#CJSJ").val();
				params["ZDYLJGID"] = userInfo["PTJGID"];
				return params;
			}
		};
	$("#qysqForm").datagrid(opt);
	
	/**禁用修改按钮*/
	$("#btnUpdate").attr("disabled", "disabled");
	
	/**加载选择方法*/
	SelectCheckBox("YLTID","qysqForm", "btnUpdate", opt);
	
	/**更新签约申请*/
	$("#btnUpdate").on("click", function(){
		var info = $("#qysqForm").datagrid("getSelections");
		if(validate(info)){
			if(info.length == 1){
				info = info[0];
				if(info["QYZT"] == "01"){
					$.QuickUrlUtils.redirectUrl("manager.html?YLTID="+info["YLTID"]);
				}else{
					$.QuickAlert.alertFail({content : "非暂存状态下的签约申请不可修改！"});
				}
			}else{
				$.QuickAlert.alertFail({content : "请选中单个签约申请！"});
			}
		}else{
			$.QuickAlert.alertFail({content : "请选中签约申请！"});
		}
	});
	
	/**查询签约申请*/
	$("#btnQuery").on("click", function(){
		queryForm();
	});
	
	/**新建签约申请*/
	$("#btnAdd").on("click", function(){
		$.QuickUrlUtils.redirectUrl("manager.html?YLJGID="+userInfo["PTJGID"]);
	});
	
	/**加入医联体*/
	/* $("#btnJoin").on("click", function(){
		$.QuickUrlUtils.redirectUrl("join?YLJGID="+userInfo["PTJGID"]);
	}); */
	
	
	/**导出签约申请*/
	$("#btnExport").on("click", function(){
		$("#ZDYLJGID").val(userInfo.PTJGID);
		$("#exportForm").submit();
	});
	
	$("#xzYljg").on("click", function(){
		//页面层
		parent.layer.open({
		  type: 1,
		  area: ["80%", "500px"], //宽高
		  scrollbar: false,
		  resize: false,
		  content: $("#yljgModal").html(),
		  move: false,
		  btn: ["确定", "取消"],
		  success: function(layero, index){
			  initYljgTable(layero);
		  },
		  yes: function (index, layero) {
          			var info = $(layero).find("#yljgForm").datagrid("getSelected")
         			$("#YLJGMC").val(info["YLJGMC"]);
			  		$("#YLJGID").val(info["PTJGID"]);
			  		parent.layer.close(index);//这块是点击确定关闭这个弹出层
          }
		});
	});
	
}

/**操作格式化*/
function operateFormatter(value, row, index) {
	var tool = $("#tableToolBar").html();
	return tool.replace(/#index#/g,index);
}

/**详细按钮*/
function detail(index){
	/**清除所有选择*/
	$("#qysqForm").datagrid("clearSelections");
	/**选中当前行*/
	$("#qysqForm").datagrid("selectRow", index);
	/**获取选中行数据*/
	var row = $("#qysqForm").datagrid("getSelected", index);
	if(row["JGLX"]=="2"){
		$.QuickUrlUtils.redirectUrl("detail.html?YLTID="+row["YLTID"]+"&YLJGID="+row["YLJGID"]);
	}else{
		$.QuickUrlUtils.redirectUrl("detail.html?YLTID="+row["YLTID"]);
	}
}

/** 查看协议 按钮 */
function queryXy(index){
	$("#qysqForm").datagrid("clearSelections");
	$("#qysqForm").datagrid("selectRow", index);
	/**获取选中行数据*/
	var select = $("#qysqForm").datagrid("getSelected");
	if(select.QYZT=='01'){
		$.QuickAlert.alertFail({content: '还未添加协议'});
	}else{
		StoreCache.setCache("ckxyData", select);
		$.QuickUrlUtils.redirectUrl("ckxy.html");
	}
}


/**获取状态*/
function getZt(zt){
	if(zt == "01"){
		zt = "暂存";
	}
	else if(zt == "02"){
		zt = "待接收";
	}
	else if(zt == "03"){
		zt = "已签约";
	}
	else if(zt == "04"){
		zt = "拒绝";
	}
	else if(zt == "05"){
		zt = "已到期";
	}
	return zt;
}

/**校验是否选中签约申请*/
function validate(info){
	if(StringUtils.isEmpty(info)){
		return false;
	}else{
		return true;
	}
}

var start = {
	    elem: '#KSSJ',
	    choose: function(datas){
	    	end.min = datas; //开始日选好后，重置结束日的最小日期
	    	end.start = datas; //将结束日的初始值设定为开始日
	    }
	};
var end = {
	    elem: '#JSSJ',
	    choose: function(datas){
	    	start.max = datas; //结束日选好后，重置开始日的最大日期
	    }
	};
</script>

<body class="easyui-layout" >

<div region="north" style="border: none; overflow: hidden;">
		<h4 class="h4-title" style="text-align:center;margin:0;padding:0;font-size: 18px;">
			新建医联体
		</h4>
	</div>
	<div region="center" style="border: none;">
<!-- 		<form id="exportForm" action="export" enctype="multipart/form-data"> -->
<!-- 			<input name="YLTIDS" id="YLTIDS" style="display: none;"> -->
<!-- 		</form> -->
		<div id="dgFormToolbar" style="background: white;">
			<form id="exportForm" action="export.service" enctype="multipart/form-data">
				<table class="form-table" style="margin:0;padding:0;">
					<tr>
						<td class="td-text">签约机构：</td>
						<td class="td-content">
							<div style="display: inline;">
								<input type="hidden" name="ZDYLJGID" id="ZDYLJGID"/>
								
								<input id="YLJGMC" class="form-control dataField" readonly="readonly" style="width: 55%;"/>
								<input  style="display: none;" id="YLJGID" name="YLJGID">
								<!-- 按钮触发模态框 -->
								<button class="btn" type="button"  style="width: 36%;"  id="xzYljg">选择</button>
							</div>
						</td>
						<td class="td-text">医联体类型：</td>
						<td class="td-content">
							<select id="YLTLX" name="YLTLX" class="form-control" cacheTable="TB_ZY_YLTLX">
							</select>
						</td>
						</td>
						
						<td class="td-text">申请时间：</td>
						<td class="td-content">
							 <input id="CJSJ" name="CJSJ" style="width:85%;height:30px;"
								class="input-text laydate-icon dataField" onclick="laydate()" />
							<!-- - <input id="JSSJ" name="JSSJ" style="width:35%;height:30px;"
								class="input-text laydate-icon dataField" onclick="laydate(end)" /> -->
						</td>
						<td class="td-text" style="text-align:center;width:160px;">
							<button id="btnQuery" class="btn btn-info" type="button" >查询</button>
						</td>
					</tr>
				</table>
			</form>
			<div style="margin:10px 10px auto 0px;">
				<button id="btnExport" class="btn btn-info" type="button">导出</button>
				<button id="btnAdd" class="btn btn-info" type="button">新建医联体</button>
				<!-- <button id="btnJoin" class="btn btn-info" type="button">加入医联体</button> -->
				<button id="btnUpdate" class="btn btn-info" type="button">修改申请</button>
			</div>
		</div>
		<div class="easyui-layout" style="border: none;">
			<div region="center" style="border: none;">
				<table id="qysqForm">
				</table>
			</div>
		</div>
	</div>
</body>
<script type="text/html" id="tableToolBar">
<a class="detail tableToolBarBtn" href="javascript:detail(#index#)" title="详细" >详细</a>
&nbsp;&nbsp;
<a class="detail tableToolBarBtn" href="javascript:queryXy(#index#)" title="查看协议" >查看协议</a>
</script>
</html>



